package com._520it.wms.web.controller;

import com._520it.wms.domain.Department;
import com._520it.wms.query.QueryObject;
import com._520it.wms.service.IDepartmentService;
import com._520it.wms.util.JSONResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by HASEE on 2017/11/14.
 */
@Controller
@RequestMapping("/department")
public class DepartmentContorller {
    @Autowired
    private IDepartmentService departmentService;

    @RequestMapping("/list")
    @RequiresPermissions("dept:list")
    public String list(Model model, QueryObject qo) {
        //int a = 1/0; 异常解析器
        model.addAttribute("pageResult", departmentService.query(qo));
        return "/department/list";
    }

    @RequestMapping("/input")
    @RequiresPermissions("dept:input")

    public String input(Long id, Model model) {
        if (id != null) {
            Department department = departmentService.get(id);
            model.addAttribute("department", department);
        }
        return "/department/input";
    }

    @RequestMapping("delete")
    @ResponseBody
    @RequiresPermissions("dept:delete")

    public JSONResult delete(Long id) {
        if (id != null) {
            departmentService.delete(id);
        }
        return new JSONResult();
    }

    @RequestMapping("/saveOrUpdate")
    @RequiresPermissions("dept:saveOrUpdate")
    public String saveOrUpdate(Department department) {
        departmentService.saveOrUpdate(department);
        return "redirect:/department/list.do";
    }


}
